<template>
<!-- 作业查询模块-任务查询-银保通任务状态查询页面 -->
    <div class="fillcontain">
        <!-- 查询条件 -->
        <div class="fastQuery">
            <el-row>
                <el-col :span="2" class="fastQuery_title"><i class="el-icon-tickets"></i><span> 查询条件</span></el-col>
                <el-col :span="10"></el-col>
                <el-col :span="4" class="moreCondition">
                    <span v-if="!isShow" @click="showorhide">更多条件 <i class="el-icon-d-arrow-right"></i></span>
                    <span v-if="isShow" @click="showorhide">收起 <i class="el-icon-d-arrow-left"></i></span>
                </el-col>
                <el-col :span="8"></el-col>
            </el-row>
        </div>
        <el-form v-show="isShow" :model="searchParams"  label-width="100px" class="search_container">
            <el-row>
                <el-col :span="6" class="common-box">
					<el-form-item label="分公司" prop="orgId">
						<el-select v-model="searchParams.orgId" placeholder="分公司" clearable>
							<el-option v-for="item in companylist" :key="item.SORGID" :label="item.SORGNAME" :value="item.SORGID"></el-option>
						</el-select>
					</el-form-item>
                </el-col>
				<el-col :span="6" class="common-box">
                    <el-form-item label="险种类型" prop="risk">
						<el-select v-model="searchParams.risk" placeholder="险种类型" clearable>
							<el-option v-for="item in insmains" :key="item.value" :label="item.name" :value="item.value">
							</el-option>
						</el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="受理号" prop="caseno">
						<el-input v-model="searchParams.caseno" placeholder="受理号" clearable></el-input>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input v-model="searchParams.chdrnum" placeholder="保单号"  oninput="if(value.length>8) value=value.slice(0,8)"  clearable></el-input>
					</el-form-item>
                 </el-col>
                
                <el-col :span="6" class="common-box">
					<el-form-item label="组号" prop="groupno">
						<el-input v-model="searchParams.groupno" placeholder="组号" clearable></el-input>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="text_center">
                    <el-button type="primary" icon="el-icon-search" @click="search"></el-button>
                    <el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <div class="contain">
        <!-- 查询结果 -->
          <div class="table_container">
            <el-table
                 v-loading="loading"
                 :data="tableData"
                 highlight-current-row
                 header-cell-class-name="table-header-class"
                 style="width:100%">
                 <el-table-column
                type="selection">
                </el-table-column>
                <el-table-column
               min-width="100"
                    property="REMARK05"
                    label="外包商"
                    align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="120"
                   property="SCHKOUSRID"
                   label="检出人"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="80"
                   property="SCASENO"
                   label="受理号"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="SCHDRNUM"
                   label="保单号码"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="SINSURED"
                   label="被保险人"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="SRISK"
                   label="险种类型"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="120"
                   property="SINSREQT"
                   label="文件类型"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="80"
                   property="SGROUPNO"
                   label="组号"
                   align='center'
                    sortable
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="120"
                   property="SDEPOTNO"
                   label="存仓号"
                   sortable
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="80"
                   property="FLAG03"
                   label="银保通"
					:formatter="isYB"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                   property="FLAG01"
                   min-width="80"
                   label="现金单"
					:formatter="isCrash"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="SORGNAME"
                   label="分支公司"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="160"
                   property="SDEALTIME"
                   label="开始时间"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="REMARK01"
                   label="多保单标记"
                   align='center'
                   show-overflow-tooltip>
				   <template slot-scope="scope">
					   <span type="primary"  v-if="scope.row.REMARK01 == ''">无
					   </span>
				       <span type="primary" style="cursor: pointer;" @click="showTwoCaseList(scope.row.STASKNO,scope.row.SCASENO)" v-if="scope.row.REMARK01 && scope.row.REMARK01 != ''">{{scope.row.REMARK01}}
				       </span>
				   </template>
                </el-table-column>
                <el-table-column
                min-width="120"
                   property="SREMARK"
                   label="最新备注"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="100"
                   property="SNODEDES"
                   label="任务状态"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="80"
                   label="处理过程"
                   align='center'
                   show-overflow-tooltip>
                   <template slot-scope="scope">
                        <el-button type="text" size="small" @click="showTaskChange(scope.row.STASKNO)" :disabled="!interceptVip(scope.row,scope.index)">处理过程</el-button>
                    </template>
                </el-table-column>
                <el-table-column
                min-width="80"
                   property="idNo"
                   label="比对结果"
                   align='center'
                   show-overflow-tooltip>
                   <template slot-scope="scope">
                        <el-button type="text" size="small" @click="showBankContrast(scope.row.STASKNO)" :disabled="!interceptVip(scope.row,scope.index)">比对结果</el-button>
                    </template>
                </el-table-column>
                <el-table-column
               min-width="80"
                   label="差错记录"
                   align='center'>
                    <template slot-scope="scope">
                         <el-button type="text" size="small" @click="showErrorList(scope.row.STASKNO)" :disabled="!interceptVip(scope.row,scope.index)">差错记录</el-button> 
                    </template>
                </el-table-column>
                <el-table-column
                    min-width="50"
                    fixed="right"
                   label="备注"
                   align='center'>
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="showRemark(scope.row.STASKNO)" :disabled="!interceptVip(scope.row,scope.index)">备注</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row>
                <el-col :span="24">
                    <div class="pagination">
                        <el-pagination
                            background
                            v-if='paginations.total > 0'
                            :page-sizes="paginations.pageSizes"
                            :page-size="paginations.pageSize"
                            :layout="paginations.layout"
                            :total="paginations.total"
                            :current-page='paginations.pageIndex'
                            @current-change='handleCurrentChange'
                            @size-change='handleSizeChange'>
                        </el-pagination>
                    </div>
                </el-col>
            </el-row>
          </div>
        </div>
        <!-- 任务流向记录 -->
        <cdfs-task-change-list :taskNo="taskChangeTaskNo" :drawer="showTaskChangeFlag" @close="hideTaskChange"></cdfs-task-change-list>
        <!-- 备注 -->
        <cdfs-remark-list :taskNo="remarkTaskNo" :drawer="showRemarkFlag" @close="hideRemark"></cdfs-remark-list>
        <!-- 比对结果 -->
        <bank-contrast-result :taskNo="bankContrastTaskNo" :drawer="showBankContrastFlag" @close="hideBankContrast"></bank-contrast-result>
		<!-- 同客户多保单-->
		<cdfs-two-case-list :taskno="twoCaseTaskno" :applnum="twoCaseApplNum" :drawer="showTwoCaseListFlag" @close="hideTwoCaseList"></cdfs-two-case-list>
    </div>
</template>

<script>
	import TaskConstants,{call} from "@/api/taskManager/common"
	import {getCdfsAuthCode} from "@/api/taskCenter/taskCommon";
	import {getCompanylist,} from "@/api/taskManager/distributeTask";
	import CdfsRemarkList from "../../taskCenter/cdfsRemarkList";
	import CdfsTaskChangeList from "../../taskCenter/CdfsTaskChangeList";
	import BankContrastResult from "@/page/homeWorkQuery/taskQuery/bankContrastResult";
	import CdfsTwoCaseList from "../../taskCenter/cdfsTwoCaseList";
    import constant from '@/utils/constant';
	import appName from "@/api/appName.js";
	import  {
		isCntainChinese,
		isNotNumber
	} from "@/api/refund/RefundCommon";
    export default {
		components:{
			CdfsRemarkList,
			CdfsTaskChangeList,
			BankContrastResult,
			CdfsTwoCaseList
		},
        data(){
            return {
                isShow:false,
                // 查询条件
				insmains: TaskConstants.insmain, //险种类型
				emptySearchParams:{},
				companylist:[],
                searchParams:{
                    orgId:'', 
                    risk:'', 
                    caseno: '', 
                    chdrnum: '', 
                    groupno: '', 
					pageNumber:'',
					pageSize:'',
                },
				href:'',
                loading:false,
                tableData:[],
				//流轉記錄
				taskChangeTaskNo:'',
				showTaskChangeFlag: false,
				twoCaseApplNum: "",
				twoCaseTaskno: "",
				showTwoCaseListFlag: false,
				//備注
				remarkTaskNo: "",
				showRemarkFlag: false,
				//对比结果
				showBankContrastFlag:false,
				bankContrastTaskNo:"",
              //需要给分页组件传的信息
                paginations: {
                    total: 0,        // 总数
                    pageIndex: 1,  // 当前位于哪页
                    pageSize: 10,   // 1页显示多少条
                    pageSizes: [5, 10, 15, 20],  //每页显示多少条
                    layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
                },
            }
        },
		activated(){
		    document.onkeydown = (event)=>{
		        var e = event || window.event || arguments.callee.caller.arguments[0];
		        if (e && e.keyCode == 113) {
		            this.search();
		        }
		    };
		}, 
        created(){
			this.emptySearchParams= JSON.parse(JSON.stringify(this.searchParams));
			// this.getList();
        },
        mounted(){
            getCompanylist().then(data =>this.companylist =data);
        },
        methods: {
			showTwoCaseList(taskno,applnum) {
			    this.twoCaseTaskno = taskno;
			    this.twoCaseApplNum = applnum;
			    this.showTwoCaseListFlag = true;
			},
			hideTwoCaseList() {
			    this.twoCaseTaskno = '';
			    this.twoCaseApplNum = '';
			    this.showTwoCaseListFlag = false;
			},
			isYB(row){
				if(row.FLAG03=='0'){
					return "否";
				}
				if (row.FLAG03 =='1'){
					return "是"
				}
				if(row.FLAG03 ==""){
					return "";
				}
                if(row.FLAG03.indexOf('*') !== -1){
                    return "*";
                }
				return "异常数据";
			},
			isCrash(row){
				if(row.FLAG01=='N'){
					return "否";
				}
				if (row.FLAG01 =='Y'){
					return "是"
				}
				if(row.FLAG01 ==""){
					return "";
				}
                if(row.FLAG03.indexOf('*') !== -1){
                    return "*";
                }
				return "异常数据";
			},
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			showErrorList(taskno) {
                // vip数据管控start
                if(taskno.indexOf("*") !== -1){
                    this.$message({
                        message: '该数据为vip保单,暂无操作权限!',
                        type: 'error'
                    });
                    return false
                }
                // vip数据管控end
				//通过字典明细表中定义的sdd_code列名称获取第三方平台路径
				const appContextUrl = JSON.parse(sessionStorage.getItem(constant.APP_CONTEXT_URL));
				if (appContextUrl == null) {
				    this.$message.error("请重新登录后重试！");
				    return;
				}
				const citicgis = appContextUrl['CITICGIS'];
				getCdfsAuthCode().then(res => {
					if (res.resultCode == constant.SUCCESS && res.data) {
						let userID = res.data.userId;
						if (userID ==undefined ||""==userID){
							userID="CHN0000095";
						}
					 let href = citicgis+`/mistakeManager?requestType=list&authCode=${res.data.authCode}&loginUserId=`+userID+`&taskno=`+taskno;
					 window.open(href,'_blank');
					}else {
						this.$message.error(res.resultMsg);
					}
				}).catch(error => {
					this.$message.error("获取CDFS差错登记出错");
				});
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
            showorhide() {
                this.isShow = !this.isShow;
            },
			resetSearch(){
				this.searchParams= JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			search(){
				if(this.searchParams.chdrnum !="" ){
					if ( isNotNumber(this.searchParams.chdrnum) || this.searchParams.chdrnum.length !=8) {
						this.$message.error("请正确输入保单号！");
						return;
					}
					
				}
				if(this.searchParams.caseno !="" ){
					if ( isNotNumber(this.searchParams.caseno)) {
						this.$message.error("请正确输入受理号！");
						return;
					}
				}
				if(this.searchParams.groupno !="" && isCntainChinese(this.searchParams.groupno)){
					this.$message.error("请正确输入组号！");
					return;
				}
				this.getList();
			},
            // 查询列表
            getList(){
				this.paginations.total = 0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				this.show();
                call(TaskConstants.apis['bankTaskQuery'],this.searchParams,"post").then(res => {
                    this.cancle();
                    if(res.resultCode == constant.SUCCESS && res.data && res.data.list.length){
                        this.paginations.total = res.data.total;
                        this.tableData = res.data.list;
                    }else {
						this.$message.error("无符合条件任务！");
					}
                   
                }).catch(err =>{
					console.log(err);
                    this.cancle();
                })
            },
			showRemark(taskNo) {
                // vip数据管控start
                if(taskNo.indexOf("*") !== -1){
                    this.$message({
                        message: '该数据为vip保单,暂无操作权限!',
                        type: 'error'
                    });
                    return false
                }
                // vip数据管控end
				this.remarkTaskNo = taskNo;
				this.showRemarkFlag = true;
			},
			hideRemark() {
				this.remarkTaskNo = "";
				this.showRemarkFlag = false;
			},
			showTaskChange(taskNo) {
                // vip数据管控start
                if(taskNo.indexOf("*") !== -1){
                    this.$message({
                        message: '该数据为vip保单,暂无操作权限!',
                        type: 'error'
                    });
                    return false
                }
                // vip数据管控end
				this.taskChangeTaskNo = taskNo;
				this.showTaskChangeFlag = true;
			},
			hideTaskChange() {
				this.taskChangeTaskNo = "";
				this.showTaskChangeFlag = false;
			},
            showBankContrast(taskNo) {
                // vip数据管控start
                if(taskNo.indexOf("*") !== -1){
                    this.$message({
                        message: '该数据为vip保单,暂无操作权限!',
                        type: 'error'
                    });
                    return false
                }
                // vip数据管控end
				this.bankContrastTaskNo = taskNo;
				this.showBankContrastFlag = true;
			},
			hideBankContrast() {
				this.bankContrastTaskNo = "";
				this.showBankContrastFlag = false;
			},
            // 每页多少条切换
            handleSizeChange(pageSize) {
               this.paginations.pageSize = pageSize;
               this.getList();
            },
            // 上下分页
            handleCurrentChange(page) {
               this.paginations.pageIndex = page;
               this.getList();
            },
            // vip权限拦截
      		interceptVip(row,index) {
          		let rowStr = JSON.stringify(row);
          		if (rowStr.indexOf("*") > -1) {
            		return false;
          		}
          		return true;
      		},
        },
    }
</script>

<style lang="less" scoped>
    .fillcontain{
        padding-bottom: 0;
        .fastQuery {
            padding: 15px 20px 10px 20px;
            background: #fff;
            border-bottom: 1px solid #e1e1e1;
            .fastQuery_title {
                color: #666;
                padding: 6px 0px;
            }
            .fastQuery_item {
                margin: 0 10px;
            }
            .item_default {
                .el-button {
                    color: #409EFF !important;
                    border-color: #c6e2ff !important;
                    background-color: #ecf5ff !important;
                }

            }
            .moreCondition {
                color: #68a3fc;
                cursor: pointer;
                padding: 6px 0px;

                .el-icon-d-arrow-right {
                    transform: rotate(90deg);
                }

                .el-icon-d-arrow-left {
                    transform: rotate(-90deg);
                }
            }
        }
    }
    .contain{
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }
   .pagination{
       padding: 10px 20px;
       text-align: right;
   }
   .operationIcon{
        // padding: 12px;
        border:1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px; 
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow:0 0 3px #f9f9f9;
   }
   .search_container{
       padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
   }
   .common-box{
        padding-bottom: 10px;
    }
    .common-lab{
        line-height:normal!important;
        text-align: right;
        .labelName{
            text-align: right;
        }
    }
</style>



